<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="加工号" prop="docNum">
        <el-input
          v-model="queryParams.docNum"
          placeholder="请输入加工号模糊查询"
          clearable
          @keyup.enter.native="handleQuery"
          style="width: 240px"
        />
      </el-form-item>
      <el-form-item label="开始时间">
        <el-date-picker
          v-model="queryParams.dtDocStart"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="起始日期"
          end-placeholder="截止日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间">
        <el-date-picker
          v-model="queryParams.dtDocFinish"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="起始日期"
          end-placeholder="截止日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['mes:work:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['mes:work:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['mes:work:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['mes:work:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="workList" :highlight-current-row="true" @selection-change="handleSelectionChange" stripe>
      <el-table-column type="selection" width="50" align="center" fixed="left"/>
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" class="demo-table-expand">
            <el-form-item label="备注：">
              <span>{{ props.row.docNote }}</span>
            </el-form-item>
            <el-form-item label="审核人：">
              <span>{{ props.row.confirmNickName }}</span>
            </el-form-item>
            <el-form-item label="审核结果：">
              <dict-tag :options="dict.type.oa_dict_confirm_status" :value="props.row.oaDictConfirmStatus"/>
            </el-form-item>
            <el-form-item label="审核时间：">
              <span>{{ props.row.confirmDt }}</span>
            </el-form-item>
            <el-form-item label="审核意见：">
              <span>{{ props.row.confirmNote }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="派工时间" align="center" prop="docDt" width="150"/>
      <el-table-column label="加工号" align="center" prop="docNum" width="160"/>
      <el-table-column label="工序类型" align="center" prop="mesDictProcessType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_type" :value="scope.row.mesDictProcessType"/>
        </template>
      </el-table-column>

      <el-table-column label="工序名称" align="center" prop="mesDictProcessName">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_name" :value="scope.row.mesDictProcessName"/>
        </template>
      </el-table-column>

      <el-table-column label="工序内容" align="center" prop="processContent" width="120" />

      <el-table-column label="工序符号" align="center" prop="mesDictProcessCode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_dict_process_code" :value="scope.row.mesDictProcessCode"/>
        </template>
      </el-table-column>

      <el-table-column label="设备类型" align="center" prop="wmsDictDeviceType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_dict_device_type" :value="scope.row.wmsDictDeviceType"/>
        </template>
      </el-table-column>

      <el-table-column label="物料名称" align="center" prop="itemName" width="180" :show-overflow-tooltip="true" />
      <el-table-column label="物料编码" align="center" prop="itemNum" width="180" :show-overflow-tooltip="true" />
      <el-table-column label="规格" align="center" prop="itemSpecification" width="120"/>

      <el-table-column label="数量" align="center" prop="workQty" />

      <el-table-column label="计量单位" align="center" prop="wmsDictMeasuringUnit" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_dict_measuring_unit" :value="scope.row.wmsDictMeasuringUnit"/>
        </template>
      </el-table-column>

      <el-table-column label="开始日期" align="center" prop="dtStart" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dtStart, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="完成日期" align="center" prop="dtDone" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dtDone, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="派工号" align="center" prop="dispatchDocNum" width="150">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="show_dispatch(scope.row)"
          >{{scope.row.dispatchDocNum}}<i class="el-icon-caret-right"></i>
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="标准定额" align="center" prop="quotaWorkingHours" width="120" />

      <el-table-column label="经办人" align="center" prop="attentionUserName" width="150px"/>
      <el-table-column label="需质检" align="center" prop="sysYesNoQc">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_yes_no" :value="scope.row.sysYesNoQc"/>
        </template>
      </el-table-column>

      <el-table-column label="审核状态" align="center" prop="oaDictConfirmStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.oa_dict_confirm_status" :value="scope.row.oaDictConfirmStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="已完成" align="center" prop="sysYesNoDone" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.sysYesNoDone"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="180">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['mes:work:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mes:work:remove']"
            :disabled="scope.row.oaDictConfirmStatus !='editing'">删除</el-button>

          <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)" v-hasPermi="['com:dropdown:more']">
            <span class="el-dropdown-link">
              <i class="el-icon-d-arrow-right el-icon--right"></i>更多
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="showDialog_confirm" icon="el-icon-success"
                                v-hasPermi="['oa:confirm:edit']"
                                :disabled="scope.row.oaDictConfirmStatus !='waiting'">审核</el-dropdown-item>
              <el-dropdown-item command="setDone" icon="el-icon-s-flag"
                                v-hasPermi="['com:single:done']"
                                :disabled="scope.row.oaDictConfirmStatus !='pass'">完成</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改加工单对话框 -->
    <el-dialog v-dialogDrag v-dialogDragWidth :title="title" :visible.sync="open" width="800px" append-to-body :close-on-click-modal=false>
      <el-form ref="form" :model="form"  label-width="100px" :rules="rules_work">

        <el-alert v-show="form.oaDictConfirmStatus != 'editing'"
                  style="margin-bottom: 15px;"
                  :title="form.latestTaskInfo"
                  type="info"
                  :closable="false"
                  effect="dark"
        >
        </el-alert>
        <el-tabs type="border-card" class="mb20">
          <el-tab-pane label="加工单信息">
            <el-row>


              <el-col :span="24">
                <el-form-item label="派工单" prop="fkMesDispatchUuid">
                  <el-input v-model="form.fkMesDispatchUuid" v-show="false"/>
                  <el-input placeholder="请点击右侧按钮选择派工单"
                            v-model="form.selectedDispatch"
                            class="input-with-select"
                            :style="{width: '100%'}">
                    <el-button type="info" plain
                               @click="showDialog_selectDispatch(form)"
                               slot="append"
                               icon="el-icon-search"
                    ></el-button>
                  </el-input>
                </el-form-item>
              </el-col>


              <el-col :span="24">
                <el-form-item label="工序" prop="fkMesProcessExecDetailUuid">
                  <el-input v-model="form.fkMesProcessExecDetailUuid" v-show="false"/>
                  <el-input placeholder="请点击右侧按钮选择工序"
                            v-model="form.selectedProcessExecDetail"
                            class="input-with-select"
                            :style="{width: '100%'}">
                    <el-button type="info" plain
                               @click="showDialog_selectProcessExecDetail"
                               slot="append"
                               icon="el-icon-search"
                    ></el-button>
                  </el-input>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item prop="quotaQtyMin">
                  <span slot="label">
                    标准定额
                   <el-tooltip content="工艺施工中的定额（单位：分钟）只读" placement="top">
                    <i class="el-icon-question"></i>
                    </el-tooltip>
                  </span>

                  <el-input placeholder="请先选择工序" v-model="form.quotaQtyMin" readOnly>
                    <template slot="append">分钟</template>
                  </el-input>

                </el-form-item>
              </el-col>


              <el-col :span="12">
                <el-form-item prop="workQty" label="数量">
                  <el-input-number v-model="form.workQty"  placeholder="请输入数量" :style="{width:'100%'}" @input="inputChange"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="加工号" prop="docNum">
                  <el-input v-model="form.docNum" placeholder="请输入加工单单据编号"/>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="单据时间" prop="docDt">
                  <el-date-picker clearable size="small"
                                  v-model="form.docDt"
                                  type="datetime"
                                  placeholder="选择单据时间"
                                  :style="{width: '100%'}" clearable>
                  </el-date-picker>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item prop="fkAttentionUserId">
                  <span slot="label">经办人
                    <el-tooltip content="括号内数字为用户ID"><i class="el-icon-question"></i></el-tooltip>
                  </span>
                  <el-input v-model="form.fkAttentionUserId" v-show="false"/>
                  <el-input placeholder="请选择经办人" v-model="form.attentionUserName" class="input-with-select">
                    <el-button @click="showDialog_selectAttentionUser( form )" slot="append"
                               icon="el-icon-search"></el-button>
                  </el-input>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item prop="totalQuotaQtyMin">
                  <span slot="label">
                    总定额
                   <el-tooltip content="总定额：单位定额*数量，不用填写，自动带出" placement="top">
                    <i class="el-icon-question"></i>
                    </el-tooltip>
                  </span>
                  <el-input placeholder="请先选择工序" v-model="form.totalQuotaQtyMin" readOnly>
                    <template slot="append">分钟</template>
                  </el-input>
                </el-form-item>
              </el-col>

            </el-row>

          </el-tab-pane>

          <el-tab-pane label="备注信息">

            <el-row>
              <el-col :span="24">
                <el-form-item label="备注" prop="docNote">
                  <el-input v-model="form.docNote"
                            type="textarea"
                            autosize
                            placeholder="请输入备注内容"
                            :style="{width: '100%'}"
                            maxlength="50"
                            show-word-limit/>
                </el-form-item>
              </el-col>
            </el-row>
          </el-tab-pane>
        </el-tabs>

        <el-divider content-position="center">加工单（员工）信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddMesWorkWorkers">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteMesWorkWorkers">删除</el-button>
          </el-col>
        </el-row>
        <el-table :data="mesWorkWorkersList" :row-class-name="rowMesWorkWorkersIndex" @selection-change="handleMesWorkWorkersSelectionChange" ref="mesWorkWorkers">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="排序序号" prop="orderNum">
            <template slot-scope="scope">
              <el-input v-model="scope.row.orderNum" placeholder="请输入排序序号" />
            </template>
          </el-table-column>
          <el-table-column label="员工姓名" prop="workerName" align="center" width="400">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fkUserIdWorker" v-show="false"/>
              <el-input placeholder="请选择员工" v-model="scope.row.workerName"
                        class="input-with-select">
                <el-button @click="showDialog_selectWorker(scope)" slot="append" icon="el-icon-search"></el-button>
              </el-input>
            </template>
          </el-table-column>
          <el-table-column label="标准定额(分钟)" prop="quotaWorkingHours">
            <template slot-scope="scope">
              <el-input v-model="scope.row.quotaWorkingHours" placeholder="请输入工时" />
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :disabled="form.oaDictConfirmStatus != 'editing'">确 定</el-button>
        <el-button type="warning" @click="submitForm('waiting')" :disabled="form.oaDictConfirmStatus != 'editing'">提交待审
        </el-button>
          <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <confirm ref="component_confirm" @ok="confirm_done()"/>
    <select-process-exec-detail ref="component_selectProcessExecDetail" @ok="selectProcessExecDetail_done"/>
    <select-dispatch ref="component_selectDispatch" @ok="selectDispatch_done"/>
    <select-user ref="component_selectAttentionUser" @ok="selectAttentionUser_done"/>
    <select-user ref="component_selectWorker" @ok="selectWorker_done"/>

  </div>
</template>

<script>
import { listWork, getWork, delWork, addWork, updateWork } from "@/api/mes/work";
import confirm from "../../oa/confirm";
import selectProcessExecDetail from "../processExecDetails/selectProcessExecDetail";
import selectDispatch from "../dispatch/selectDispatch";
import selectUser from "../../comn/userGroup/selectUser";
import {parseTime} from "@/utils/ruoyi";
import {newDocNum} from "@/api/oa/docNum";

export default {
  name: "Work",
  dicts: ['sys_normal_disable', 'oa_dict_confirm_status', 'mes_dict_process_type', 'mes_dict_process_name',
    'mes_dict_process_code','wms_dict_measuring_unit','sys_yes_no','wms_dict_device_type'],
  components: { confirm,selectProcessExecDetail,selectUser,selectDispatch },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedMesWorkWorkers: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 加工单表格数据
      workList: [],
      // 加工单（员工）表格数据
      mesWorkWorkersList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fkMesDispatchUuid: null,
        fkMesProcessExecDetailUuid: null,
        workQty: null,
        quotaWorkingHours: null,
        sysNormalDisable: null,
        docTitle: null,
        docNum: null,
        docDt: null,
        docNote: null,
        fkAttentionUserId: null,
        fkConfirmUserId: null,
        confirmDt: null,
        oaDictConfirmStatus: null,
        confirmNote: null,
      },
      // 表单参数
      form: {},
      rules_work: {
        fkMesDispatchUuid: [
          {required: true, message: "派工单不能为空", trigger: "change"}
        ],
        fkMesProcessExecDetailUuid: [
          {required: true, message: "工序不能为空", trigger: "change"}
        ],
        workQty: [
          {required: true, message: "数量不能为空", trigger: "change"}
        ],
        sysNormalDisable: [
          {required: true, message: "状态不能为空", trigger: "change"}
        ],
        docNum: [
          {required: true, message: "单据编号不能为空", trigger: "change"}
        ],
        docDt: [
          {required: true, message: "单据时间不能为空", trigger: "change"}
        ],
        fkAttentionUserId: [
          {required: true, message: "经办人ID不能为空", trigger: "change"}
        ],
        oaDictConfirmStatus: [
          {required: true, message: "审核状态不能为空", trigger: "change"}
        ],
        createBy: [
          {required: true, message: "创建者不能为空", trigger: "change"}
        ],
        createTime: [
          {required: true, message: "创建时间不能为空", trigger: "change"}
        ],
      },
    };
  },
  created() {

    // $route params
    let workDocNum = this.$route.params && this.$route.params.workDocNum;
    if (workDocNum) {
      this.queryParams.docNum = workDocNum
    }else console.log('！！！ 无参数 ！！！')

    this.getList();
  },
  methods: {

    inputChange(){
      console.log(this.form.workQty)
      console.log(this.form.quotaQtyMin)
      if(this.form.quotaQtyMin == undefined){
        this.form.quotaQtyMin=0
      }
      this.form.totalQuotaQtyMin=this.form.workQty*this.form.quotaQtyMin
    },

    /** 打开对话框：审核 */
    showDialog_confirm(row) {
      console.log(row)
      let obj = {
        tableName: 'mes_work',
        uuidColumn: 'mes_work_uuid',
        fkUuid: row.mesWorkUuid,
        attentionUserNickName: row.attentionUserName,
        oaDictConfirmStatus: row.oaDictConfirmStatus,
        msg: `请审核加工单, 加工号：${row.docNum}`
      }
      this.$refs.component_confirm.showDialog_confirm(obj);

    },

    confirm_done() {

      this.getList()
    },
    /** 查询加工单列表 */
    getList() {
      this.loading = true;
      if (this.queryParams.dtDocStart) {
        this.queryParams.dtDocStartBegin = this.queryParams.dtDocStart[0]
        this.queryParams.dtDocStartEnd = this.queryParams.dtDocStart[1]
      } else {
        this.queryParams.dtDocStartBegin = null
        this.queryParams.dtDocStartEnd = null
      }
      if (this.queryParams.dtDocFinish) {
        this.queryParams.dtDocFinishBegin = this.queryParams.dtDocFinish[0]
        this.queryParams.dtDocFinishEnd = this.queryParams.dtDocFinish[1]
      } else {
        this.queryParams.dtDocFinishBegin = null
        this.queryParams.dtDocFinishEnd = null
      }
      listWork(this.queryParams).then(response => {
        this.workList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        mesWorkUuid: null,
        fkMesDispatchUuid: null,
        selectedDispatch: null,
        fkMesProcessExecDetailUuid: null,
        quotaWorkingHours: null,
        sysNormalDisable: null,
        docTitle: null,
        workQty: 1,
        docNum: null,
        docDt:parseTime(Date.now(), '{y}-{m}-{d} {h}:{i}'),
        docNote: null,
        fkAttentionUserId: null,
        fkConfirmUserId: null,
        confirmDt: null,
        oaDictConfirmStatus: null,
        confirmNote: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        dispatchDocNum: null
      };
      this.mesWorkWorkersList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.mesWorkUuid)
      this.docDts = selection.map(item => item.docDt)
      this.docNums = selection.map(item => item.docNum)
      this.single = selection.length!==1
      this.oaDictConfirmStatus = selection.map(i=>i.oaDictConfirmStatus)
      this.multiple=
        (this.oaDictConfirmStatus.indexOf('editing')>-1 && [...new Set(this.oaDictConfirmStatus)]=='editing') ? false : true
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();

      newDocNum({preCode: 'WRK-', len: 12}).then(response => {
        this.form.docNum = response.msg
      })
      this.form.oaDictConfirmStatus = 'editing'
      this.open = true;
      this.title = "添加加工单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const mesWorkUuid = row.mesWorkUuid || this.ids
      getWork(mesWorkUuid).then(response => {
        this.form = response.data;
        console.log(this.form)
        this.mesWorkWorkersList = response.data.mesWorkWorkersList;
        this.form.selectedDispatch =`派工号：${this.form.dispatchDocNum}   `
        this.form.selectedProcessExecDetail = ` 符号：${this.selectDictLabel(this.dict.type.mes_dict_process_code,this.form.mesDictProcessCode)} / ` +
          `名称：${this.selectDictLabel(this.dict.type.mes_dict_process_name, this.form.mesDictProcessName)} / 类型：${this.selectDictLabel(this.dict.type.mes_dict_process_type, this.form.mesDictProcessType)}`

        this.form.oaDictConfirmStatus =
          ('editing' == this.form.oaDictConfirmStatus || 'reject' == this.form.oaDictConfirmStatus)
            ? 'editing' : this.form.oaDictConfirmStatus


        if(row.oaDictConfirmStatus!='editing'||row.oaDictConfirmStatus!='reject'||this.oaDictConfirmStatus!='editing'||this.oaDictConfirmStatus!='reject'){
          this.form.latestTaskInfo='💡 该条记录审核状态为'+
            this.selectDictLabel(this.dict.type.oa_dict_confirm_status, row.oaDictConfirmStatus||this.oaDictConfirmStatus)+'状态'+','+'不能修改'
        }

        this.open = true;
        this.title = "修改加工单";
      });
    },
    /** 提交按钮 */
    submitForm(confirmStatus) {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if(confirmStatus=='waiting') this.form.oaDictConfirmStatus = confirmStatus
          this.form.mesWorkWorkersList = this.mesWorkWorkersList;
          if (this.form.mesWorkUuid != null) {
            updateWork(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWork(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const mesWorkUuids = row.mesWorkUuid || this.ids;
      const docDts = row.docDt || this.docDts;
      const docNums = row.docNum || this.docNums;
      this.$modal.confirm('是否确认删除派工时间为"' + docDts + '",加工号为"'+docNums+'"的加工单？','删除确认').then(function() {
        return delWork(mesWorkUuids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
	/** 加工单（员工）序号 */
    rowMesWorkWorkersIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 加工单（员工）添加按钮操作 */
    handleAddMesWorkWorkers() {
      let obj = {};
      obj.orderNum = "";
      obj.fkUserIdWorker = "";
      obj.quotaWorkingHours = "";
      obj.workerName="",
      this.mesWorkWorkersList.push(obj);
    },
    /** 加工单（员工）删除按钮操作 */
    handleDeleteMesWorkWorkers() {
      if (this.checkedMesWorkWorkers.length == 0) {
        this.$modal.msgError("请先选择要删除的加工单（员工）数据");
      } else {
        const mesWorkWorkersList = this.mesWorkWorkersList;
        const checkedMesWorkWorkers = this.checkedMesWorkWorkers;
        this.mesWorkWorkersList = mesWorkWorkersList.filter(function(item) {
          return checkedMesWorkWorkers.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleMesWorkWorkersSelectionChange(selection) {
      this.checkedMesWorkWorkers = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('mes/work/export', {
        ...this.queryParams
      }, `mes_work.xlsx`)
    },

    // 显示 - 总计划
    show_dispatch(r) {
      console.log(r)
      this.$router.push(`/mes/dispatch/docNum/${r.dispatchDocNum}`);
    },

    /** 显示对话框：选择工序 */
    showDialog_selectProcessExecDetail() {
      console.log(this.form.processExecUuid)
      this.$refs.component_selectProcessExecDetail.processExecUuid = this.form.processExecUuid
      this.$refs.component_selectProcessExecDetail.show();
    },

    /** 显示对话框：选择工序 */
    selectProcessExecDetail_done(detail) {
      console.log(detail)
      this.form.fkMesProcessExecDetailUuid = detail.processExecDetailUuid
      this.form.quotaQtyMin = detail.quotaQtyMin
      this.form.selectedProcessExecDetail = `序号：${detail.orderNum} / 符号：${detail.mesDictProcessCode} / ` +
        `名称：${detail.mesDictProcessName} / 类型：${detail.mesDictProcessType}`
    },

    /** 选择经办人 */
    showDialog_selectAttentionUser(form) {
      this.currentForm = form
      this.$refs.component_selectAttentionUser.userGroup = 'worker';
      this.$refs.component_selectAttentionUser.show();
    },


    /** 选择经办人 - 完成 */
    selectAttentionUser_done(user) {
      this.currentForm.fkAttentionUserId = user.userId
      this.currentForm.attentionUserName = user.userNickNameAndId
    },

    /** 选择派工单 */
    showDialog_selectDispatch(form) {
      this.currentForm = form
      this.$refs.component_selectDispatch.showDialog_selectDispatch();
    },


    /** 选择派工单 - 完成 */
    selectDispatch_done(user) {
      console.log(user)
      this.currentForm.processExecUuid = user.processExecUuid
      this.currentForm.fkMesDispatchUuid = user.dispatchUuid
      this.currentForm.selectedDispatch =  `派工号：${user.docNum} / 派工时间：${user.docDt}  `
      console.log( this.currentForm.processExecUuid)
    },

    /** 显示对话框：选择工人 */
    showDialog_selectWorker(scope) {
      this.currRowScope = scope
      this.$refs.component_selectWorker.userGroup = 'worker';
      this.$refs.component_selectWorker.show();
    },

    /** 选择工人 - 完成 */
    selectWorker_done(user) {
      this.currRowScope.row.fkUserIdWorker = user.userId
      this.currRowScope.row.workerName = user.userNickNameAndId
    },



    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "showDialog_confirm":
          this.showDialog_confirm(row);
          break;
        case "setDone":
          let id = row.mesWorkUuid

          this.$modal.confirm( `是否确认加工号号为 ${row.docNum} 的加工单已完成？`, '完成确认').then(function() {
            let d = {
              mesWorkUuid: id,
              sysYesNoDone: row.sysYesNoDone == 'Y' ? 'N':'Y'
            }

            return updateWork(d).then(response => {
            });

          }).then(() => {
            this.$modal.msgSuccess("修改成功");
            this.getList();
          }).catch(() => {});

          break;
        default:
          break;
      }
    },

  }
};
</script>
